package com.example.usage.aop.log;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @author jiangzhe
 * @create 2022/9/1 15:55
 */
@Aspect
@Component
@Slf4j
@Order(2)
public class OptLogAspect2 {

    @Pointcut("execution(* com.example.usage.aop.log.WorkService.*(..))")
    public void pointCut(){}

    @Before("pointCut()")
    public void before(){
        log.info("OptLogAspect2 -- before");
    }

    @AfterReturning(pointcut = "pointCut()", returning = "jsonObj")
    public void afterReturning(JoinPoint joinPoint, Object jsonObj){
        String args = Arrays.toString(joinPoint.getArgs());
        log.info("OptLogAspect2 -- afterReturning args: {}, res: {}", args, jsonObj);
    }
}
